<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="账号">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" type="password"></el-input>
      </el-form-item>
      <div id="wMa">
        <span><a href="javascript:void (0)" @click="wMa">忘记密码?</a></span>
      </div>
      <el-form-item>
        <el-button type="primary" @click="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

  export default {
    name: "AdminLogin",
    data() {
      return {
        form: {
          username: '',
          password: '',
          flag: '',
        },
        admin: {},
      }
    },
    methods: {
      wMa() {
        alert(1);
      },
      submit() {
        this.$axios.post('/admin/login', this.form)
          .then(resp => {
            const result = resp.data;
            if (result.code === 'success') {
              // this.$store.dispatch('login',resp.data)
              sessionStorage.setItem('user', JSON.stringify(result.data));
              this.$message.success(result.message);
              this.$router.push('/hello')
            } else {
              this.$message.error(result.message);
            }
          })
      }
    },

  }
</script>

<style scoped>
  div {
    width: 180px;
    margin: 0 auto;
  }
</style>
